const mysql = require('mysql');

//第二步
let mysqlObj = mysql.createConnection({ host: "127.0.0.1", user: 'root', password: '', port: 3306, database: 'xiao_u' });

//第三步
mysqlObj.connect();


function exec(sqls) {
    return new Promise((resolve, reject) => {
        mysqlObj.query(sqls, (err, data) => {
            if (err) { //sql执行失败
                resolve([false, 'sql执行失败']);
            } else {
                resolve([true, data]);
            }
        });

    });
}


//暴露
module.exports = exec